import { getAccessToken } from '@/services/login'
import store from '@/store/index'

async function postInfo () {
  const { data } = await getAccessToken({
    appid: window.localStorage.getItem('appid'),
    secret: window.localStorage.getItem('secret'),
    grant_type: 'client_credential'
  })
  store.commit('changeUser', data)
}

export const getToken = () => {
  try {
    const at = window.localStorage.getItem('access_token')
    return at
  } catch (err) {
    postInfo()
  }
}
